<?php
/**
 * Created by JetBrains NetBeans.
 * User: yinyancai
 * Date: 13-3-14 下午4:44
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}
include_once 'forum.php';
class cloud_api {
    function common() { }

    function output() {
        global $_G;
        //判断是否缺少参数
//        if (empty($_GET['uuid'])) {
//            $variable = array(
//                'code' => 1001,
//                'messagestr' => lang('plugin/cloud', '1001'),
//            );
//            cloud_core::result(cloud_core::variable($variable));
//        }
        $data = C::t('#cloud#cloud_spot')->fetch_all_limit();
		if(empty($_GET['uuid'])){
			$res = array();
		}else{
			$res = C::t('#cloud#cloud_spotsign')->fetch_all_limit($_GET['uuid']);
		}
        foreach ($data as $key => $value) {
            $data[$key]['sign'] = 0;
			//echo "<pre>"; print_r($res);exit;
            if(!empty($res)){
                foreach($res as $v){
                    if($v['spotid'] == $value['id']){
                        $data[$key]['sign'] = 1;
                    }
                }
            }
            if (!empty($value['image'])) {
                $data[$key]['image'] = $_G['siteurl'] . 'data/attachment/product/' . $value['image'];
				$data[$key]['signimage'] = $_G['siteurl'] . 'data/attachment/product/' . $value['signimage'];
            }
        }
        $result = self::array_sort($data,'id','asc');
        //正常返回
        $variable = array(
            'data' => cloud_core::getvalues($result, array('/^\d+$/')),
        );
        cloud_core::result(cloud_core::variable($variable));
    }
    //对二维数组自定义排序
    function array_sort($arr,$keys,$type){
        $keysvalue=array();
        $i = 0;
        foreach($arr as $key=>$val) {
            $val[$keys] = str_replace("-","",$val[$keys]);
            $val[$keys] = str_replace(" ","",$val[$keys]);
            $val[$keys] = str_replace(":","",$val[$keys]);
            $keysvalue[] =$val[$keys];
        }
        asort($keysvalue); //key值排序
        reset($keysvalue); //指针重新指向数组第一个
        foreach($keysvalue as $key=>$vals) {
            $keysort[] = $key;
        }
        $new_array = array();
        if($type != "asc"){
            for($ii=count($keysort)-1; $ii>=0; $ii--) {
                $new_array[] = $arr[$keysort[$ii]];
            }
        }else{
            for($ii=0; $ii<count($keysort); $ii++){
                $new_array[] = $arr[$keysort[$ii]];
            }
        }
        return $new_array;
    }
}

?>

